<?php
namespace app\h5api\controller;

use app\common\service\Wechat;
use think\facade\Config;
use think\Request;

class Cart extends Base
{
    /**
     * @route('h5/UserCartList')
     * 用户购物车列表
     */
    public function UserCartList()
    {
        $cartModel = new \app\common\model\Cart();
        $page = input('get.page');
        $data = $cartModel->get_cart_list($this->GetUserInfo(),$page,$this->limit);
//        var_dump($data);die;
        $this->result($data,1,'返回成功');
    }

    /**
     * @route('h5/UserEditCart')
     * 用户编辑购物车(添加编辑)
     */
    public function UserEditCart()
    {
        $cartModel = new \app\common\model\Cart();
        $productid = input('post.product_id');
        $stockid = input('post.stock_id');
        $quantity = input('post.quantity');
        $rs = $cartModel->editcart($this->_userid,$productid,$stockid,$quantity);
        if(!$rs){
            $this->result('',-1,$cartModel->getError());
        }
        $this->result($rs,1,'编辑成功');
    }

    /**
     * @route('h5/UserDelCart')
     * 删除购物车
     */
    public function UserDelCart()
    {
        $cartModel = new \app\common\model\Cart();
        $cartids = input('post.cart_ids');
        $cartids = implode(",", $cartids);
        $rs = $cartModel->delcart($this->_userid,$cartids);
        if(!$rs){
            $this->result('',-1,$cartModel->getError());
        }
        $this->result('',1,'删除成功');
    }
}
